<template>
    <div id="app">
        <router-view/>
    </div>
</template>

<script>
    import jwt_decode from "jwt-decode";

    export default {
        name: "app",
        data() {
            return {
            isRouterAlive: true
        }
        },
        mounted() {

        },
        created() {
            if (localStorage.eleToken) {
                const decode = jwt_decode(localStorage.eleToken);
                this.$store.dispatch("setIsAutnenticated", !this.isEmpty(decode));
                this.$store.dispatch("setUser", decode);
            }
        },
        provide() {
            return {
                reload: this.reload
            }
        },
        methods: {
            isEmpty(value) {
                return (
                    value === undefined ||
                    value === null ||
                    (typeof value === "object" && Object.keys(value).length === 0) ||
                    (typeof value === "string" && value.trim().length === 0)
                );
            },
            reload() {
                this.isRouterAlive = false
                this.$nextTick(function () {
                    this.isRouterAlive = true
                })
            }
        }
    };
</script>


<style>
    html,
    body,
    #app {
        width: 100%;
        height: 100%;
    }
</style>
